package org.zjt.chapter1.zero.copy;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufHolder;
import io.netty.buffer.DefaultByteBufHolder;
import io.netty.buffer.Unpooled;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

/**
 * Description:
 *
 * @author juntao.zhang
 * Date: 2018-07-11 下午5:05
 * @see
 */
@Slf4j
public class NettyByteBufHolder {

    @Test
    public void main() {
        ByteBuf byteBuf = Unpooled.wrappedBuffer("ssss".getBytes());
        ByteBufHolder byteBufHolder = new DefaultByteBufHolder(byteBuf);

        ByteBuf content = byteBufHolder.content();
        byte[] data = new byte[content.readableBytes()];

        content.readBytes(data);
        log.info(new String(data));

        content.readerIndex(0);

        content.readBytes(data);
        log.info(new String(data));


    }
}
